#
# Copyright (C) 2013 Will Dignazio
#
ROOTDIR = $(PWD)
PREFIX	= $ROOTDIR

CC	= clang
CFLAGS	= -O0 -g -Wall -Werror -D_FILE_OFFSET_BITS=64 -I $(ROOTDIR)/include/
LIBS	= -lfuse -lssl -lcrypto -lleveldb

ULIBS	= libmstore	\
	  libutil	\

CSRC	= ucache.c	\
	  db.c		\
	  fuse.c	\
	  obj.c		\
	  disk.c	\

COBJ	= $(CSRC:.c=.o)
CLIBS	= $(ULIBS:=.a)

export ROOTDIR
export CFLAGS
export CC

.PHONY: all clean check

all: $(COBJ) $(CLIBS) 
	$(CC) $(CFLAGS) $(LIBS) -o ucache $(COBJ) $(CLIBS)

%.o: %.c internal.h
	$(CC) $(CFLAGS) -c -o $@ $<

%.a:
	export LOCALDIR=$(ROOTDIR)/$*
	$(MAKE) $(MAKEFLAGS) -C $*
	cp $*/$@ ./

check: all
	$(MAKE) $(MAKEFLAGS) -C check

clean:
	@for lib in $(ULIBS); do	\
		$(MAKE) -C $$lib clean;	\
	done
	$(MAKE) -C check clean

	rm -f *.a
	rm -f *.o
	rm -f ucache
